<template>
    <div class="icons">
      <swiper :options="swiperOption">
        <swiper-slide  v-for="(page,index) of pages" :key="index">
          <div class="icon" v-for="item of page" :key="item.id">
            <div class="icon-wrapper">
              <img :src="item.imgUrl" alt="item.desc"/>
            </div>
            <p class="icon-text">{{item.desc}}</p>
          </div>
        </swiper-slide>
        <div class="swiper-pagination "  slot="pagination"></div>
      </swiper>
    </div>
</template>

<script>
export default {
  name: 'HomeIcons',
  props: {
    iconList: Array
  },
  data () {
    return {
      swiperOption: {
        autoplay: false,
        loop: true,
        pagination: '.swiper-pagination'
      }
    }
  },
  computed: {
    pages () {
      let pages = []
      this.iconList.forEach((item, index) => {
        let vIndex = Math.floor(index / 8)
        if (!pages[vIndex]) {
          pages[vIndex] = []
        }
        pages[vIndex].push(item)
      })
      return pages
    }
  }
}
</script>

<style scoped lang="stylus">
  @import "~styles/variables.styl";
  @import "~styles/mixins.styl";
.icons
  width:100%;
  padding-bottom:50%;
  overflow:hidden;
  height:0
  .icon
    width:25%;
    float:left;
    padding-bottom:25%;
    position:relative;
    height:0
    .icon-wrapper
      position:absolute;
      left:0;
      right:0;
      top:0;
      bottom:.44rem;
      overflow:hidden;
      padding:.04rem
      img
        display:block;
        height:90%;
        position:absolute;
        left:0;
        right:0;
        margin:auto;
        top:0;
        bottom:0;
    .icon-text
      position:absolute;
      left: 0;
      right: 0;
      bottom:0;
      height:.44rem;
      line-height:.44rem;
      color:$darkTextColor;
      text-align:center;
      ellipsis()
</style>
